package com.sc.utils;

public class MathUtil {

	/**
	 * 解决double乘法精度错误
	 * 
	 * @param num1
	 * @param num2
	 * @return
	 */
	public static double mult(double num1, double num2) {
		String n1 = String.valueOf(num1), n2 = String.valueOf(num2);
		int length1 = getLength(n1), length2 = getLength(n2);
		return ((double) ((int) (num1 * getInteger(length1)) * (int) (num2 * getInteger(length2))))
				/ getInteger(length1 + length2);
	}

	private static int getLength(String num) {
		return num.indexOf(".") == -1 ? 0 : num.split("\\.")[1].length();
	}

	private static long getInteger(int length) {
		long l = 1;
		for (int i = 0; i < length; i++) {
			l *= 10;
		}
		return l;
	}

}
